package com.zheng.damo01.作业;

public class Test11 {
    public static void main(String[] args) {
        String str = "aaaaccbbhhhhhhh";
        char[] chars=new char[24];
        int[] arr=new int[24];
        int index=0;
        char[] chars1 = str.toCharArray();
        for (int i = 0; i < chars1.length; i++) {
            if (chars1[i]>='a'&&chars1[i]<='z'||chars1[i]>='A'&&chars1[i]<='Z'){
                if (getChar(chars1[i],chars)){
                    chars[index]=chars1[i];
                    arr[index]++;
                    index++;
                }else {
                    arr[getIndex(chars1[i],chars)]++;
                }
            }
        }
        int max=0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[max]<arr[i]){
                max=i;
            }
        }
        System.out.println("次数最多的是"+chars[max]+"次数为"+arr[max]);

    }
    public static boolean getChar(char c,char[] chars){
        for (int i = 0; i < chars.length; i++) {
            if (chars[i]==c){
                return false;
            }
        }
        return true;
    }
    public static int getIndex(char c,char[] chars){
        for (int i = 0; i < chars.length; i++) {
            if (chars[i]==c){
                return i;
            }
        }
        return -1;
    }
}
